<?php namespace Home\Model;
use Hdphp\Model\Model;
//支付模型
class Payment extends Model{
	
	protected $table = "record";
	
	protected $validate = array(
		
	);
	protected $auto = array(
		array('pay_time','time','function',3,1),
	);
	
	
	//把数据添加到夺宝记录表
	public function addData($data){
		
		if($this->create()) return false;
		
		
		//查看打印出来的随机数******************
//		foreach ($data['goods'] as $k => $v) {
//			//每次循环都要有一个新的空字符串。不然每次循环就会把之前的连接上
//			$num = '';
//			for ($i=0; $i < $v['num']; $i++) { 
//				$num .= mt_rand(1000, 9999) . ',';
//			}
//			$number[] = $num;
//		}
//	
//		sp($number);exit;
		//这里是循环把购物车自动生成的键名改成从0开始的键名
		foreach ($data['goods'] as $k => $v) {
			unset($data['goods'][$k]);
			$data['goods'][]=$v;
		}
//		sp($data);
		
		foreach ($data['goods'] as $k => $v) {
			//每次循环都要有一个新的空字符串。不然每次循环就会把之前的连接上
			$num = '';
			for ($i=0; $i < $v['num']; $i++) { 
				$num .= mt_rand(10000001, 10099999) . ',';
			}
			$num = substr($num, 0,strlen($num)-1);
			
			$number[] = $num;
//			sp($number);

			$temp = array(
				'pay_time'=>time(),
				'random_num'=>$number[$k],
				'total' => $v['num'],
				'user_uid'=> $_SESSION['userid'],
				'goods_gid'=> $v['id'],
				'goods_periods_gpid'=> 0,
			);
			$this->add($temp);
		}
		
		return true;
	}
	
}



 ?>